from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from .ser import *


# Create your views here.


class ClassifyM(APIView):
    def post(self, request):
        ser = ClassifySer(data=request.data)
        if ser.is_valid():
            ser.save()
            return Response({'code': 200})
        return Response({'code': 10010})

    def get(self, request):
        gain = Classify.objects.all()
        ser = ClassifySer(gain, many=True)
        return Response({'code': 200, 'matter': ser.data})


class GoodsM(APIView):
    def post(self, request):
        ser = GoodSer(data=request.data)
        if ser.is_valid():
            ser.save()
            return Response({'code': 200})
        return Response({'code': 10010})

    def get(self, request):
        gain = Goods.objects.all()
        ser = ShowGoods(gain, many=True)
        return Response({'code': 200, 'matter': ser.data})